using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for FormsAdaptor.
	/// </summary>
	public class FormsAdaptor : Adaptor, IRefreshable
	{
    private FreeFlow.Administration.FormCollection forms;
    public FormsAdaptor(FreeFlow.Administration.FormCollection forms)
		{
      this.forms = forms;
    }

    public override void AddChildren(TreeNode node)
    {
      foreach (FreeFlow.Administration.Form form in forms)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new FormAdaptor(form));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 4;
      }
    }

    public override string Text
    {
      get
      {
        return "Forms (" + forms.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      FormsControl control = new FormsControl();
      control.LoadForms(forms);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return forms;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      forms.Refresh();
    }

    #endregion
  }
}
